package com.singzi.leetcode.jianzhiOffer;

import com.singzi.leetcode.obj.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class T0032_3 {
}
class Solution {
    List<List<Integer>> list = new ArrayList<>();
    public List<List<Integer>> levelOrder(TreeNode root) {

        if(root == null) return list;
        visitZTree(root, 0);
        return list;
    }

    private void visitZTree(TreeNode root, int k) {
        if(list.size()<k) list.add(new ArrayList<>());
        list.get(k).add(root.val);
    }
}
